package com.wk1un2.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wk1un2.entity.Product;
import com.wk1un2.entity.ProductSpec;
import com.wk1un2.service.ProductService;
import com.wk1un2.service.ProductSpecService;
import com.wk1un2.util.Result;

/**
 *商品规格控制
 * 
 * @author Administrator
 *
 */
@Controller
public class ProductSpecController {
	@Autowired
	ProductSpecService service;

	@RequestMapping("/Backstage/getAllProductSpec")
	@ResponseBody
	public Object getAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("ps_color") String ps_color, @RequestParam("ps_price") String ps_price) {

		if (ps_color == null || ps_color == "") {
			ps_color = null;
		}
		if (ps_price == null || ps_price == "") {
			ps_price = null;
		}

		List<Map<String, Object>> ls = service.getAll((page - 1) * limit, limit, ps_color, ps_price);
		Result res = new Result(0, "", service.count(), ls);
		return res;
	}

//	增
	@RequestMapping("/Backstage/addProductSpec")
	@ResponseBody
	public Object add(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("ps_color"));
		System.out.println(map.get("ps_price"));
		int i = service.add(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	改
	@RequestMapping("/Backstage/updateProductSpec")
	@ResponseBody
	public Object update(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("ps_color"));
		System.out.println(map.get("ps_price"));
		int i = service.update(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	删
	@RequestMapping("/Backstage/deleteProductSpec")
	@ResponseBody
	public Object delete(@RequestParam("ps_id") int ps_id) {
		System.out.println(ps_id);
		int i = service.delete(ps_id);
		Result res = new Result(0, "", i, i);
		return res;
	}
}